package com.definity.toolkit.ui.widget.paint;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JComponent;

public class GradientPaint implements Paint {

	private final int top;
	private final Color c1;
	private final Color c2;

	private GradientPaint(int top, Color c1, Color c2) {
		this.top = top;
		this.c1 = c1;
		this.c2 = c2;
	}
	
	public static synchronized Paint create(Color c1, Color c2) {
		return new GradientPaint(0, c1, c2);
	}

	public static synchronized Paint create(int topGap, Color c1, Color c2) {
		return new GradientPaint(topGap, c1, c2);
	}

	@Override
	public void paint(Graphics2D g, Component c) {
		if (c.isOpaque())
			((JComponent) c).setOpaque(false);
			
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		
		java.awt.GradientPaint gradient = new java.awt.GradientPaint(0, top, c1, top, c.getHeight(), c2);
		g.setPaint(gradient);
		g.fillRect(0, 0, c.getWidth(), c.getHeight());
	}

}
